<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 12-10-3
 * Time: 下午12:56
 * To change this template use File | Settings | File Templates.
 */
class HomeController extends Jwawa_BaseController
{
    public function indexAction()
    {
        $this->_helper->layout->enableLayout();
        $view_renderer = $this->_helper->getHelper("viewRenderer");
        $view_renderer->setNoRender(false);

        if ($this->getSessionBag() != null
                && $this->getSessionBag()->getLoginAccountId() != null) {
            $this->view->sessionBag = $this->getSessionBag();
        } else {
            $this->_redirect('/');
        }
    }

    public function findUserMenuTreeAction()
    {
        $menu_tree = Model_Cfg_Menus::findUserMenuTree($this->getSessionBag()->getloginAccountId());

        $rst = new Jwawa_ResponseBaseDto($menu_tree);
        $json = Zend_Json::encode($rst);
        echo $json;
    }

    public function changePwdAction()
    {
        throw new Jwawa_BusinessException('PWD_CHG_FAILED');
    }

    public function getLogonMenuAction(){
        $profiles = Model_Cfg_LgnAcntProfile::findProfileValuesByKey(
            $this->getSessionBag()->getLoginAccountId(),
            'logonMenuId');
        if(count($profiles) == 1){
            $menuId = intval($profiles[0]->attr_value);
            $menu = Model_Cfg_Menus::getMenuById($menuId);
            if($this->getSessionBag()->getUserActionCodeMap()[$menu->action_code]){
                $rst = new Jwawa_ResponseBaseDto($menu);
            } else {
                $rst = new Jwawa_ResponseBaseDto();
            }
        } else {
            $rst = new Jwawa_ResponseBaseDto();
        }

        $json = Zend_Json::encode($rst);
        echo $json;
    }
}
